package hotel.modal;

import hotel.dao.UserDao;
import javafx.beans.property.*;

public class User {
	private SimpleStringProperty userName; 		// 登录用户名
	private SimpleStringProperty password;		// 登录密码
	private SimpleIntegerProperty employeeId;	// 员工编号
	private SimpleBooleanProperty admin;		// 是否管理员
	private SimpleBooleanProperty modified;
	
	private void init(UserDao ud) {
		if(ud != null) {
			this.userName = new SimpleStringProperty(ud.getUserName());
			this.password = new SimpleStringProperty(ud.getPassword());
			this.employeeId = new SimpleIntegerProperty(ud.getEmployeeId());
			this.admin = new SimpleBooleanProperty(ud.getAdmin());
		}else {
			this.userName = new SimpleStringProperty("");
			this.password = new SimpleStringProperty("");
			this.employeeId = new SimpleIntegerProperty(0);
			this.admin = new SimpleBooleanProperty(false);
		}
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public User(UserDao ud) {
		init(ud);
	}
	
	public User() {
		init(null);
	}
	
	public Object getDao() {
		UserDao ud = new UserDao();
		ud.setUserName(userName.get());
		ud.setPassword(password.get());
		ud.setEmployeeId(employeeId.get());
		ud.setAdmin(admin.get());
		return ud;
	}
	
	public User(User user) {
		this.userName = new SimpleStringProperty(user.getUserName());
		this.password = new SimpleStringProperty(user.getPassword());
		this.employeeId = new SimpleIntegerProperty(user.getEmployeeId());
		this.admin = new SimpleBooleanProperty(user.isAdmin());
		this.modified = new SimpleBooleanProperty(user.isModified());
	}
	
	public User(String userName, String password, Integer employeeId, int admin) {
		this.userName = new SimpleStringProperty(userName);
		this.password = new SimpleStringProperty(password);
		this.employeeId = new SimpleIntegerProperty(employeeId);
		if(admin > 0) this.admin = new SimpleBooleanProperty(true);
		else this.admin = new SimpleBooleanProperty(false);
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public final SimpleStringProperty userNameProperty() {
		return this.userName;
	}
	
	public final String getUserName() {
		return this.userNameProperty().get();
	}
	
	public final void setUserName(final String userName) {
		this.userNameProperty().set(userName);
	}
	
	public final SimpleStringProperty passwordProperty() {
		return this.password;
	}
	
	public final String getPassword() {
		return this.passwordProperty().get();
	}
	
	public final void setPassword(final String password) {
		this.passwordProperty().set(password);
	}
	
	public final SimpleIntegerProperty employeeIdProperty() {
		return this.employeeId;
	}
	
	public final int getEmployeeId() {
		return this.employeeIdProperty().get();
	}
	
	public final void setEmployeeId(final int employeeId) {
		this.employeeIdProperty().set(employeeId);
	}
	
	public final SimpleBooleanProperty adminProperty() {
		return this.admin;
	}
	
	public final boolean isAdmin() {
		return this.adminProperty().get();
	}
	
	public final void setAdmin(final boolean admin) {
		this.adminProperty().set(admin);
	}
	
	public String toString() {
		String str = "UserName: " + userName.get() + " Password: " + password.get() + " EmployeeID: " + 
				String.valueOf(employeeId.get()) +" Admin: " + admin.get() + " Modified: " + modified.get();
		return str;
	}

	public final SimpleBooleanProperty modifiedProperty() {
		return this.modified;
	}
	

	public final boolean isModified() {
		return this.modifiedProperty().get();
	}
	

	public final void setModified(final boolean modified) {
		this.modifiedProperty().set(modified);
	}
	
}
